package com.doit.day02

import com.doit.day02.OrderInfo

import scala.util.Sorting

object _02_scala的比较器 {
  def main(args: Array[String]): Unit = {
    val arr = Array(
    new ScalaOrder("o001", "u001", "c001", 99.99, 2),
    new ScalaOrder("o003", "u003", "c003", 89.99, 4),
    new ScalaOrder("o005", "u005", "c005", 59.99, 5),
    new ScalaOrder("o006", "u006", "c006", 49.99, 7),
    new ScalaOrder("o004", "u004", "c004", 79.99, 6),
    new ScalaOrder("o002", "u002", "c002", 69.99, 3),
    new ScalaOrder("o008", "u008", "c008", 39.99, 9),
    new ScalaOrder("o007", "u007", "c007", 9.99, 1)
    )

    Sorting.quickSort(arr)/*(new Ordering[ScalaOrder] {
      override def compare(x: ScalaOrder, y: ScalaOrder) = -x.price.compare(y.price)
    })*/

    arr.foreach(println)

  }
}

case class ScalaOrder(val oid:String,val uid:String,val cid:String,val price:Double,val good_num:Int) extends Ordered[ScalaOrder] {
  override def compare(that: ScalaOrder): Int = -that.price.compare(this.price)
}
